package org.darkforest.merchant.ajaxTemplete.impl;

import org.darkforest.enums.AjaxAlbumTypeEnum;
import org.darkforest.merchant.ajaxTemplete.AlbumAjaxPage;
import org.darkforest.model.AlbumPic;
import org.darkforest.model.AlbumPicPageBean;

/**
 * Created by valentina on 15/3/19.
 * 添加商品第二步商品描述详情返回code
 */
public class GoodsStep2DescAlbum extends AlbumAjaxPageTemplete implements AlbumAjaxPage {

    public GoodsStep2DescAlbum() {
        this.insertType = AjaxAlbumTypeEnum.EDITOR.getText();
    }

    @Override
    protected String getPicListCode(AlbumPicPageBean picPage ,Integer specSize) {
        String tpl ="";
        if(picPage.getResultList()!=null && picPage.getResultList().size()>0){
            tpl +=  "<ul class='list'>";
            //循环出图片信息 js需要用双引号否则不执行
            for (AlbumPic pic:picPage.getResultList()){
                tpl +=   "      <li onclick=\"insert_"+insertType+"(";
                //pc端编辑插入原图
                tpl +=   "'"+aliyun_path+"/"+pic.getApicCover()+"');\">" ;
                tpl +=   "           <a href='JavaScript:void(0);'><img src='"+aliyun_path+"/60_"+pic.getApicCover()+"' title='"+pic.getApicName()+"'/></a></li>" ;
            }
            tpl +=  "</ul>";
        }else{
            tpl += "<div class='warning-option'><i class='icon-warning-sign'></i><span>相册中暂无图片</span></div>";
        }
        return tpl;
    }

    @Override
    protected String getScriptCode() {

        String tpl = "";
        tpl += "<script type=\"text/javascript\">";
        tpl += "$(document).ready(function(){";

        tpl += "    $('.demo').ajaxContent({" +
                "       event:'click'," +
                "       loaderType:'img'," +
                "       loadingMsg:'" + basePath + "/resources/images/loading.gif'," +
                "       target:'#des_demo'" +
                "   });";
        //选择相册触发的js
        tpl += "    $('#jumpMenu_" + insertType + "').change(function(){" +
                "       var url = '" + getAjaxUrl() + "&albumId='+$('#jumpMenu_" + insertType + "').val();" +
//                    "       alert(\"-----\"+url);" +
                "       $('#select_submit_" + insertType + "').attr('href',url);" +
                "        $('.sample_demo').ajaxContent({" +
                "            event:'click', " +
                "            loaderType:'img'," +
                "            loadingMsg:'" + basePath + "/resources/images/loading.gif'," +
                "            target:'#des_demo'" +
                "        });" +
                "       $('#select_submit_" + insertType + "').click();" +
                "   });";

        tpl += "});" +
                "</script>";
        return tpl;
    }
}
